<?php

namespace common\rest\controllers;

use Yii;
use yii\helpers\ArrayHelper;
use common\rest\controllers\ActiveController as BaseController;

/**
 * AuthActiveController
 */
class AuthActiveController extends BaseController {

    public $serializer = [
        'class' => 'common\rest\components\Serializer',
        'collectionEnvelope' => 'data',
    ];

    // public function actions() {
    //     $actions = [
    //         'index' => [
    //             'class' => 'yii\rest\IndexAction',
    //             'modelClass' => $this->modelClass,
    //             'checkAccess' => [$this, 'checkAccess'],
    //             'prepareDataProvider' => [$this, 'prepareDataProvider'],
    //         ],
    //         'view' => [
    //             'class' => 'yii\rest\ViewAction',
    //             'modelClass' => $this->modelClass,
    //             'checkAccess' => [$this, 'checkAccess'],
    //         ],
    //         'create' => [
    //             'class' => 'yii\rest\CreateAction',
    //             'modelClass' => $this->modelClass,
    //             'checkAccess' => [$this, 'checkAccess'],
    //             'scenario' => $this->createScenario,
    //         ],
    //         'update' => [
    //             'class' => 'yii\rest\UpdateAction',
    //             'modelClass' => $this->modelClass,
    //             'checkAccess' => [$this, 'checkAccess'],
    //             'scenario' => $this->updateScenario,
    //         ],
    //         'delete' => [
    //             'class' => 'yii\rest\DeleteAction',
    //             'modelClass' => $this->modelClass,
    //             'checkAccess' => [$this, 'checkAccess'],
    //         ],
    //         'options' => [
    //             'class' => 'yii\rest\OptionsAction',
    //         ],
    //     ];
    //     return $actions;
    // }

    public function behaviors() {
        return ArrayHelper::merge(parent::behaviors(), [
                    'authenticator' => [
                        'class' => \common\rest\filters\auth\CompositeAuth::className(),
                        'authMethods' => [
                            \common\rest\filters\auth\HttpBearerAuth::className(),
                            // \common\rest\filters\auth\QueryParamAuth::className(),
                        ],
                    ],
                    'access' => [
                        'class' => \yii\filters\AccessControl::className(),
                        'rules' => [
                            [
                                // 'actions' => ['login',],
                                'allow' => true,
                            ],
                            [
                                'roles' => ['@'],
                                'allow' => true,
                            ],
                        ],
                    ],
        ]);
    }

    protected function verbs() {
        return [
            'index' => ['POST', 'GET', 'HEAD'],
            'view' => ['POST', 'GET', 'HEAD'],
            'create' => ['POST'],
            'update' => ['POST', 'PUT', 'PATCH'],
            'delete' => ['POST','DELETE'],
        ];
    }

}
